﻿using System.Collections.Generic;
namespace GX
{
    public interface IService
    {
    }
    public static class App
    {
        public const int SERVICE_DATA_MANAGER = 1;
        public const int SERVICE_POOL_MANAGER = 2;
        public const int SERVICE_TICK_MANAGER = 3;
        public const int SERVICE_EVENT_MANAGER = 4;
        public const int SERVICE_ASSET_MANAGER = 5;
        public const int SERVICE_UI_MANAGER = 6;
        public const int SERVICE_AUDIO_MANAGER = 7;
        public const int SERVICE_MODULE_MANAGER = 8;

        static readonly Dictionary<int, IService> _serviceMap = new Dictionary<int, IService>();

        
        static public bool AddService(int serviceID, IService service)
        {
            IService existService;
            if (_serviceMap.TryGetValue(serviceID, out existService))
                return existService != service;
            _serviceMap[serviceID] = service;
            return true;
        }
        static public IService GetService(int serviceID)
        {
            IService ret = null;
            if (!_serviceMap.TryGetValue(serviceID, out ret))
            {
                if (serviceID < 1000)
                {
                    ret = GetInternalSystemService(serviceID);
                    if (null != ret)
                    {
                        _serviceMap[serviceID] = ret;
                    }
                }
            }
            return ret;
        }
        static IService GetInternalSystemService(int serviceID)
        {
            switch (serviceID)
            {
                case SERVICE_DATA_MANAGER:
                    return new DataManagerService();
                case SERVICE_POOL_MANAGER:
                    return new PoolManagerService();
                case SERVICE_TICK_MANAGER:
                    return new TickManagerService();
                case SERVICE_EVENT_MANAGER:
                    return new EventManagerService();
                case SERVICE_ASSET_MANAGER:
                    return new AssetManagerService();
                case SERVICE_UI_MANAGER:
                    return new UIManagerService();
                case SERVICE_AUDIO_MANAGER:
                    return new AudioManagerService();
                case SERVICE_MODULE_MANAGER:
                    return new ModuleManagerService();
            }
            return null;
        }
    }
    
}